<script lang="ts" setup>
	import { ref } from "vue";
	import marketingCard from '@/components/marketing-card.vue'
	import gysMarketingCard from '@/components/gys-marketing-card/gys-marketing-card.vue'
	import {
		useRouter
	} from 'uni-mini-router'
	import {
		onShow,
		onHide,
		onLoad,
		onReachBottom
	} from '@dcloudio/uni-app'
	import {
		getCurrentInstance
	} from 'vue'
	import {
		userStore
	} from '@/pinia';
	const {
		proxy,
	} = getCurrentInstance()
	const userStoreInfo = userStore();
	let searchWord = ref('')
	let marketList = ref([])
	let router = useRouter()
	let pageObj = ref({})
	onLoad((options) => {
		console.log(options);
		searchWord.value = options.key
		pageObj.value = JSON.parse(options.data)
		getMarketList()
	})
	onReachBottom(() => {
		marketPage.value++
		getMarketList()
	})
	let marketPage = ref(1)
	const getMarketList = () => {
		let url;
		if (userStoreInfo.userFlag == 2) {
			url = proxy.$api.marketList
		} else {
			url = proxy.$api.marketList2
		}
		proxy.$req('GET', url, {
			pageNo: marketPage.value,
			pageSize: 15,
			title: searchWord.value,
			vendorId: userStoreInfo.userInfo.supplier.id ? userStoreInfo.userInfo.supplier.id : '',
		}).then((res) => {
			// console.log(res, 'res');
			if (res.success) {
				marketList.value = marketList.value.concat(res.result.records)
				console.log(marketList.value, 'marketList.values');
			} else {
				uni.showToast({
					title: res.message,
					icon: 'none'
				})
			}

		})
	}
</script>
<template>
	<view class="contain">
		<view class="marketList" v-if="userStoreInfo.userFlag==2">
			<gys-marketing-card :type="'marketingDetail'" :listData="marketList"
				:screenObj="pageObj"></gys-marketing-card>
		</view>
		<view class="marketList" v-else>
			<marketing-card :type="'marketingDetail'" :listData="marketList" :screenObj="pageObj"></marketing-card>
		</view>
	</view>
</template>
<style lang="scss">
	.contain {
		width: 686rpx;
		margin: 0 auto;
	}
</style>